﻿@using Smartstore.Core.Logging;

@if (!Display.HasMessages())
{
    return;
}

<script sm-target-zone="scripts" sm-minify="true" data-origin="notifications">
    $(function () {
        var items = $("#notification-list").find("> .msg");
        items.each(function (i, el) {
            el = $(el);
            var type = el.data("type");
            var sticky = type != "success" && type != "info";
            var delay = type == "success" ? 3500 : 5000;
            var notify = function () {
                EventBroker.publish("message", {
                    text: el.html(),
                    type: type,
                    delay: delay,
                    hide: !sticky,
                    icon: true,
                    shadow: false
                });
            };
            _.delay(notify, 100 * i);
        });
    })
</script>

<div id="notification-list" class="d-none" style="position:absolute; left:-9999px">
    @foreach (var message in Display.GetMessages(NotifyType.Error))
    {
        <div class="msg" data-type="error">@Html.Raw(message)</div>
    }
    @foreach (var message in Display.GetMessages(NotifyType.Success))
    {
        <div class="msg" data-type="success">@Html.Raw(message)</div>
    }
    @foreach (var message in Display.GetMessages(NotifyType.Info))
    {
        <div class="msg" data-type="info">@Html.Raw(message)</div>
    }
    @foreach (var message in Display.GetMessages(NotifyType.Warning))
    {
        <div class="msg" data-type="warning">@Html.Raw(message)</div>
    }
</div>

<zone name="notifications"></zone>